package com.kfdx.dc.controller;

import com.kfdx.dc.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kfdx.dc.common.annotation.Log;
import com.kfdx.dc.common.core.controller.BaseController;
import com.kfdx.dc.common.core.domain.AjaxResult;
import com.kfdx.dc.common.enums.BusinessType;
import com.kfdx.dc.domain.DcOrderDetail;
import com.kfdx.dc.service.IDcOrderDetailService;
import com.kfdx.dc.common.utils.poi.ExcelUtil;
import com.kfdx.dc.common.core.page.TableDataInfo;

/**
 * 订单明细Controller
 *
 * @author cx
 * @date 2024-09-23
 */
@Api("订单明细")
@RestController
@RequestMapping("/order/detail")
public class DcOrderDetailController extends BaseController
{
    @Autowired
    private IDcOrderDetailService dcOrderDetailService;

    /**
     * 查询订单明细列表
     */
    @ApiOperation("查询订单明细列表")
    @PreAuthorize("@ss.hasPermi('order:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcOrderDetail dcOrderDetail)
    {
        startPage();
        List<DcOrderDetail> list = dcOrderDetailService.selectDcOrderDetailList(dcOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出订单明细列表
     */
    @ApiOperation("导出订单明细列表")
    @PreAuthorize("@ss.hasPermi('order:detail:export')")
    @Log(title = "订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcOrderDetail dcOrderDetail)
    {
        List<DcOrderDetail> list = dcOrderDetailService.selectDcOrderDetailList(dcOrderDetail);
        ExcelUtil<DcOrderDetail> util = new ExcelUtil<DcOrderDetail>(DcOrderDetail.class);
        util.exportExcel(response, list, "订单明细数据");
    }

    /**
     * 获取订单明细详细信息
     */
    @ApiOperation("获取订单明细详细信息")
    @PreAuthorize("@ss.hasPermi('order:detail:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(dcOrderDetailService.selectDcOrderDetailByOrderId(orderId));
    }

    /**
     * 新增订单明细
     */
    @ApiOperation("新增订单明细")
    @PreAuthorize("@ss.hasPermi('order:detail:add')")
    @Log(title = "订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcOrderDetail dcOrderDetail)
    {
        dcOrderDetail.setCreateTime(DateUtils.getNowDate());
        return toAjax(dcOrderDetailService.insertDcOrderDetail(dcOrderDetail));
    }

    /**
     * 修改订单明细
     */
    @ApiOperation("修改订单明细")
    @PreAuthorize("@ss.hasPermi('order:detail:edit')")
    @Log(title = "订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcOrderDetail dcOrderDetail)
    {
        dcOrderDetail.setUpdateTime(DateUtils.getNowDate());
        return toAjax(dcOrderDetailService.updateDcOrderDetail(dcOrderDetail));
    }

    /**
     * 删除订单明细
     */
    @ApiOperation("删除订单明细")
    @PreAuthorize("@ss.hasPermi('order:detail:remove')")
    @Log(title = "订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(dcOrderDetailService.deleteDcOrderDetailByOrderIds(orderIds));
    }
}
